home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / u_man / cat3 / Tcl / tcl.z / tcl
Encoding:
Text File  |  1998-10-30  |  8.9 KB  |  199 lines

  1.  
  2.  
  3.  
  4. TTTTccccllll((((3333TTTTccccllll))))                                                            TTTTccccllll((((3333TTTTccccllll))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      Tcl - Summary of Tcl language syntax.
  10.  
  11.  
  12. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  13.      The following rules define the syntax and semantics of the Tcl language:
  14.  
  15.      [1]  A Tcl script is a string containing one or more commands.  Semi-
  16.           colons and newlines are command separators unless quoted as
  17.           described below.  Close brackets are command terminators during
  18.           command substitution (see below) unless quoted.
  19.  
  20.      [2]  A command is evaluated in two steps.  First, the Tcl interpreter
  21.           breaks the command into _w_o_r_d_s and performs substitutions as
  22.           described below.  These substitutions are performed in the same way
  23.           for all commands.  The first word is used to locate a command
  24.           procedure to carry out the command, then all of the words of the
  25.           command are passed to the command procedure.  The command procedure
  26.           is free to interpret each of its words in any way it likes, such as
  27.           an integer, variable name, list, or Tcl script.  Different commands
  28.           interpret their words differently.
  29.  
  30.      [3]  Words of a command are separated by white space (except for
  31.           newlines, which are command separators).
  32.  
  33.      [4]  If the first character of a word is double-quote (``"'') then the
  34.           word is terminated by the next double-quote character.  If semi-
  35.           colons, close brackets, or white space characters (including
  36.           newlines) appear between the quotes then they are treated as
  37.           ordinary characters and included in the word.  Command substitution,
  38.           variable substitution, and backslash substitution are performed on
  39.           the characters between the quotes as described below.  The double-
  40.           quotes are not retained as part of the word.
  41.  
  42.      [5]  If the first character of a word is an open brace (``{'') then the
  43.           word is terminated by the matching close brace (``}'').  Braces nest
  44.           within the word: for each additional open brace there must be an
  45.           additional close brace (however, if an open brace or close brace
  46.           within the word is quoted with a backslash then it is not counted in
  47.           locating the matching close brace).  No substitutions are performed
  48.           on the characters between the braces except for backslash-newline
  49.           substitutions described below, nor do semi-colons, newlines, close
  50.           brackets, or white space receive any special interpretation.  The
  51.           word will consist of exactly the characters between the outer
  52.           braces, not including the braces themselves.
  53.  
  54.      [6]  If a word contains an open bracket (``['') then Tcl performs _c_o_m_m_a_n_d
  55.           _s_u_b_s_t_i_t_u_t_i_o_n.  To do this it invokes the Tcl interpreter recursively
  56.           to process the characters following the open bracket as a Tcl
  57.           script.  The script may contain any number of commands and must be
  58.           terminated by a close bracket (``]'').  The result of the script
  59.           (i.e. the result of its last command) is substituted into the word
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. TTTTccccllll((((3333TTTTccccllll))))                                                            TTTTccccllll((((3333TTTTccccllll))))
  71.  
  72.  
  73.  
  74.           in place of the brackets and all of the characters between them.
  75.           There may be any number of command substitutions in a single word.
  76.           Command substitution is not performed on words enclosed in braces.
  77.  
  78.      [7]  If a word contains a dollar-sign (``$'') then Tcl performs _v_a_r_i_a_b_l_e
  79.           _s_u_b_s_t_i_t_u_t_i_o_n:  the dollar-sign and the following characters are
  80.           replaced in the word by the value of a variable.  Variable
  81.           substitution may take any of the following forms:
  82.  
  83.           $$$$_n_a_m_e          _N_a_m_e is the name of a scalar variable;  the name is
  84.                          terminated by any character that isn't a letter,
  85.                          digit, or underscore.
  86.  
  87.           $$$$_n_a_m_e((((_i_n_d_e_x))))   _N_a_m_e gives the name of an array variable and _i_n_d_e_x
  88.                          gives the name of an element within that array.  _N_a_m_e
  89.                          must contain only letters, digits, and underscores.
  90.                          Command substitutions, variable substitutions, and
  91.                          backslash substitutions are performed on the
  92.                          characters of _i_n_d_e_x.
  93.  
  94.           $$$${{{{_n_a_m_e}}}}        _N_a_m_e is the name of a scalar variable.  It may
  95.                          contain any characters whatsoever except for close
  96.                          braces.
  97.  
  98.      There may be any number of variable substitutions in a single word.
  99.      Variable substitution is not performed on words enclosed in braces.
  100.  
  101.      [8]  If a backslash (``\'') appears within a word then _b_a_c_k_s_l_a_s_h
  102.           _s_u_b_s_t_i_t_u_t_i_o_n occurs.  In all cases but those described below the    |
  103.           backslash is dropped and the following character is treated as an   |
  104.           ordinary character and included in the word.  This allows characters
  105.           such as double quotes, close brackets, and dollar signs to be
  106.           included in words without triggering special processing.  The
  107.           following table lists the backslash sequences that are handled
  108.           specially, along with the value that replaces each sequence.
  109.  
  110.           \aaaa    Audible alert (bell) (0x7).                                   |
  111.  
  112.           \bbbb    Backspace (0x8).
  113.  
  114.           \ffff    Form feed (0xc).
  115.  
  116.           \nnnn    Newline (0xa).
  117.  
  118.           \rrrr    Carriage-return (0xd).
  119.  
  120.           \tttt    Tab (0x9).
  121.  
  122.           \vvvv    Vertical tab (0xb).
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. TTTTccccllll((((3333TTTTccccllll))))                                                            TTTTccccllll((((3333TTTTccccllll))))
  137.  
  138.  
  139.  
  140.           \<<<<nnnneeeewwwwlllliiiinnnneeee>>>>_w_h_i_t_e_S_p_a_c_e
  141.                 A single space character replaces the backslash, newline, and |
  142.                 all white space after the newline.  This backslash sequence is|
  143.                 unique in that it is replaced in a separate pre-pass before   |
  144.                 the command is actually parsed.  This means that it will be   |
  145.                 replaced even when it occurs between braces, and the resulting|
  146.                 space will be treated as a word separator if it isn't in      |
  147.                 braces or quotes.
  148.  
  149.           \\    Backslash (``\'').
  150.  
  151.           \_o_o_o  The digits _o_o_o (one, two, or three of them) give the octal
  152.                 value of the character.
  153.  
  154.           \xxxx_h_h  The hexadecimal digits _h_h give the hexadecimal value of the   |
  155.                 character.  Any number of digits may be present.
  156.  
  157.      Backslash substitution is not performed on words enclosed in braces,
  158.      except for backslash-newline as described above.
  159.  
  160.      [9]  If a hash character (``#'') appears at a point where Tcl is
  161.           expecting the first character of the first word of a command, then
  162.           the hash character and the characters that follow it, up through the
  163.           next newline, are treated as a comment and ignored.  The comment
  164.           character only has significance when it appears at the beginning of
  165.           a command.
  166.  
  167.      [10] Each character is processed exactly once by the Tcl interpreter as
  168.           part of creating the words of a command.  For example, if variable
  169.           substitution occurs then no further substitutions are performed on
  170.           the value of the variable;  the value is inserted into the word
  171.           verbatim.  If command substitution occurs then the nested command is
  172.           processed entirely by the recursive call to the Tcl interpreter; no
  173.           substitutions are performed before making the recursive call and no
  174.           additional substitutions are performed on the result of the nested
  175.           script.
  176.  
  177.      [11] Substitutions do not affect the word boundaries of a command.  For
  178.           example, during variable substitution the entire value of the
  179.           variable becomes part of a single word, even if the variable's value
  180.           contains spaces.
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.